﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using SanQiOther.Models;
using System.Data.Entity;

namespace SanQiOther.Controllers
{
    public class BgsCarDeptMainController : Controller
    {
        private RewardDbContext db = new RewardDbContext();
        // GET: BgsCarMain


        public ActionResult Index()
        {

            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "2019", Value = "2019" });
            items.Add(new SelectListItem { Text = "2020", Value = "2020" });
            this.ViewData["YearList"] = items;

            List<SelectListItem> itemss = new List<SelectListItem>();
            itemss.Add(new SelectListItem { Text = "1", Value = "1" });
            itemss.Add(new SelectListItem { Text = "2", Value = "2" });
            itemss.Add(new SelectListItem { Text = "3", Value = "3" });
            itemss.Add(new SelectListItem { Text = "4", Value = "4" });
            itemss.Add(new SelectListItem { Text = "5", Value = "5" });
            itemss.Add(new SelectListItem { Text = "6", Value = "6" });
            itemss.Add(new SelectListItem { Text = "7", Value = "7" });
            itemss.Add(new SelectListItem { Text = "8", Value = "8" });
            itemss.Add(new SelectListItem { Text = "9", Value = "9" });
            itemss.Add(new SelectListItem { Text = "10", Value = "10" });
            itemss.Add(new SelectListItem { Text = "11", Value = "11" });
            itemss.Add(new SelectListItem { Text = "12", Value = "12" });
            this.ViewData["MonthList"] = itemss;
            ViewBag.Dept = 0;
            ViewBag.Year = 0;
            ViewBag.Month = 0;
            return View();
        }

        [HttpPost]
        public ActionResult Index(FormCollection form)
        {

            int year = Convert.ToInt16(form["YearList"]);
            int month = Convert.ToInt16(form["MonthList"]);



            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "2018", Value = "2018" });
            items.Add(new SelectListItem { Text = "2019", Value = "2019" });
            this.ViewData["YearList"] = items;

            List<SelectListItem> itemss = new List<SelectListItem>();
            itemss.Add(new SelectListItem { Text = "1", Value = "1" });
            itemss.Add(new SelectListItem { Text = "2", Value = "2" });
            itemss.Add(new SelectListItem { Text = "3", Value = "3" });
            itemss.Add(new SelectListItem { Text = "4", Value = "4" });
            itemss.Add(new SelectListItem { Text = "5", Value = "5" });
            itemss.Add(new SelectListItem { Text = "6", Value = "6" });
            itemss.Add(new SelectListItem { Text = "7", Value = "7" });
            itemss.Add(new SelectListItem { Text = "8", Value = "8" });
            itemss.Add(new SelectListItem { Text = "9", Value = "9" });
            itemss.Add(new SelectListItem { Text = "10", Value = "10" });
            itemss.Add(new SelectListItem { Text = "11", Value = "11" });
            itemss.Add(new SelectListItem { Text = "12", Value = "12" });
            this.ViewData["MonthList"] = itemss;


            ViewBag.Year = year;
            ViewBag.Month = month;

            return View();
        }

        public ActionResult Index_1(int Year, int Month)
        {
            var member1 = db.v_bgs_car_dept_main.Where(r => r.year == Year && r.month == Month && r.carid == 1);
            var list = member1.ToList().OrderByDescending(r => r.carid);
            return View(list);
        }

        public ActionResult Index_2(int Year, int Month)
        {
            var member1 = db.v_bgs_car_dept_main.Where(r => r.year == Year && r.month == Month && r.carid == 2);
            var list = member1.ToList().OrderByDescending(r => r.carid);
            return View(list);
        }

        public ActionResult Index_3(int Year, int Month)
        {
            var member1 = db.v_bgs_car_dept_main.Where(r => r.year == Year && r.month == Month && r.carid == 3);
            var list = member1.ToList().OrderByDescending(r => r.carid);
            return View(list);
        }

        public ActionResult Index_4(int Year, int Month)
        {
            var member1 = db.v_bgs_car_dept_main.Where(r => r.year == Year && r.month == Month && r.carid == 4);
            var list = member1.ToList().OrderByDescending(r => r.carid);
            return View(list);
        }

        public ActionResult Index_5(int Year, int Month)
        {
            var member1 = db.v_bgs_car_dept_main.Where(r => r.year == Year && r.month == Month && r.carid == 5);
            var list = member1.ToList().OrderByDescending(r => r.carid);
            return View(list);
        }

        public ActionResult Detail(int id)
        {
            v_bgs_car_dept_main member = db.v_bgs_car_dept_main.FirstOrDefault(r => r.id == id);
            return View(member);
        }

        [HttpPost]
        public ActionResult Detail(v_bgs_car_dept_main Member)
        {

            SanQiOther.Models.bgs_car_dept_main bgs_car_dept_main_New = new bgs_car_dept_main();
            bgs_car_dept_main_New = db.bgs_car_dept_main.Find(Member.id);
            if (ModelState.IsValid)
            {
                db.Entry(bgs_car_dept_main_New).State = EntityState.Modified;
                bgs_car_dept_main_New.lc = Member.lc;

                db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View();
        }
    }
}